package com.anycc.cloud.core.entity;

import com.anycc.cloud.common.entity.BaseEntity;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import javax.persistence.*;

/**
 * 权限实体类
 */
@Entity
@Table(
        name = "sys_permission",
        indexes = {@Index(
                name = "i_sys_permission_name",
                columnList = "name"
        ), @Index(
                name = "i_sys_permission_sn",
                columnList = "sn"
        )}
)
public class Permission extends BaseEntity {
    private static final long serialVersionUID = 4963412057010810616L;
    public static final String MODULE_PERMISSION_SPLIT = ":";
    public static final String FIELD_NAME = "name";
    public static final String FIELD_SN = "sn";
    public static final String FIELD_MODULE = "module";
    private String name;
    private String sn;
    private Module module;

    public Permission() {
    }

    @Column(
            name = "name",
            length = 64,
            nullable = false
    )
    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Column(
            name = "sn",
            length = 36,
            nullable = false
    )
    public String getSn() {
        return this.sn;
    }

    public void setSn(String sn) {
        this.sn = sn;
    }

    @ManyToOne
    @JoinColumn(
            name = "module_id",
            referencedColumnName = "id"
    )
    @JsonIgnoreProperties({"icon", "description", "priority", "parent", "permissions", "updateTime", "createTime"})
    public Module getModule() {
        return this.module;
    }

    public void setModule(Module module) {
        this.module = module;
    }
}
